package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class GatewayDemoApplication {

    public static void main(String[] args) {
        // -Dcsp.sentinel.dashboard.server=127.0.0.1:8080 -Dcsp.sentinel.api.port=8719
//        System.setProperty("csp.sentinel.dashboard.server", "127.0.0.1:8080");
//        System.setProperty("csp.sentinel.api.port", "8719");

        // 强制使得 sentinel dashboard 中的 gateway 可以进行 请求链路/api 管理 的操作
        System.setProperty("csp.sentinel.app.type", "1");
        // 设置可以被访问的地址给sentinel服务端IP
//        System.setProperty("spring.cloud.sentinel.transport.client-ip", getV4IP());
        SpringApplication.run(GatewayDemoApplication.class, args);
    }

//    public static String getV4IP() {
//        String ip = "";
//        String chinaz = "http://ip.chinaz.com";
//
//        StringBuilder inputLine = new StringBuilder();
//        String read = "";
//        URL url = null;
//        HttpURLConnection urlConnection = null;
//        BufferedReader in = null;
//        try {
//            url = new URL(chinaz);
//            urlConnection = (HttpURLConnection) url.openConnection();
//            in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
//            while ((read = in.readLine()) != null) {
//                inputLine.append(read + "\r\n");
//            }
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (in != null) {
//                try {
//                    in.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        Pattern p = Pattern.compile("\\<dd class\\=\"fz24\">(.*?)\\<\\/dd>");
//        Matcher m = p.matcher(inputLine.toString());
//        if (m.find()) {
//            String ipstr = m.group(1);
//            ip = ipstr;
//        }
//        return ip;
//    }
}
